﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_Modules_yahoo_Edit : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.btnAddNew.Attributes.Add("onclick", "return OnSubmitClick();");
       // this.btnCancel.Attributes.Add("onclick", "return ClearAll()");
        if (!this.IsPostBack) {
            InitItem();
        }
    }
   
    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        AddNew();
        Response.Redirect(ViewState["URLReferrer"].ToString());
    }

    private void AddNew()
    {
        String strMess = "";
       
            try
            {
                int ID = -1;
                try
                {
                    ID = Convert.ToInt32(Request.Params["ID"].ToString());
                }
                catch { }
                WebData data = new WebData();
                DataLibrary.tbl_Nick_Yahoo item = new DataLibrary.tbl_Nick_Yahoo();
                item.IdNick = ID;
                item.Nickname = this.txtNickName.Text.Trim();
                item.IsActive = chkisActive.Checked==true ? 1: 0;
                item.OrderId = Convert.ToInt32(txtOrderId.Text.Trim());
                item.Description = txtDescription.Text.Trim();
                item.Phone = txtPhone.Text;
                data.tbl_Nick_Yahoos.UpdateOnSubmit(item);
                strMess = Message.Update;

            }
            catch (Exception err)
            {
                strMess = Message.Update_err + "! vì lỗi " + err.Message.ToString();
            }
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Err", "alert('" + strMess + "');", true);

    }

    private void InitItem()
    {
        int ID=-1;
        try {
            ID = Convert.ToInt32(Request.Params["ID"].ToString());
        }
        catch { }
        ViewState["URLReferrer"] = Request.UrlReferrer.AbsoluteUri;
        WebData db=new WebData();
        DataLibrary.tbl_Nick_Yahoo item = db.tbl_Nick_Yahoos.GetItemById(ID);
        if (item != null) {
            txtDescription.Text = item.Description;
            txtNickName.Text = item.Nickname;
            txtOrderId.Text = item.OrderId.ToString();
            chkisActive.Checked = item.IsActive == 1 ? true : false;
            txtPhone.Text = item.Phone;
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect(ViewState["URLReferrer"].ToString());
    }
}